<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./../../base/bmob/bmob.js"></script>
    <script src="./../../base/bmob/record.js"></script>
    <style>
        th,td {
            border: 1px solid;
        }
    </style>
</head>
<body>
<button id="ref">刷新</button>
<table style="width: 100%">
    <thead>
    <tr>
        <th>#</th>
        <th>问题</th>
        <th>答案</th>
        <th>提交</th>
    </tr>
    </thead>
    <tbody id="qn">
    </tbody>
</table>
<script>
    window.onload = function () {
        Bmob.initialize('693f7e27f97550ba','IBAS12');
        Bmob.User.login('ibas','ibas').then(console.log);
        window.record = new Record();
        document.getElementById('ref').onclick = function () {
            let qn = document.getElementById('qn');
            qn.innerHTML = '';
            window.record.getAll().then(ret => {
                ret.forEach((r,ind) => {
                    qn.innerHTML += `<tr>
<td>${ind + 1}</td>
<td>${r.question}</td>
<td><input type="text" value="${r.answer}" row="${ind}" tar="${r.objectId}" class="answer_${ind}"></td>
<td><button class="submit" tar="${r.objectId}" row="${ind}">提交</button></td>
</tr>`;
                });
            });
            setTimeout(() => {
                let sub = document.getElementsByClassName('submit');
                for (let i = 0;i < sub.length;i++) {
                    sub[i].onclick = function () {
                        let row = this.getAttribute('row');
                        let value = document.getElementsByClassName(`answer_${row}`)[0].value;
                        let id = this.getAttribute('tar');
                        window.record.update(id,value);
                    }
                }
            },1000);
        };
    }
</script>
</body>
</html>
